package com.central.scheduler.spi.params.input;

import com.central.scheduler.spi.params.base.PluginParams;
import com.central.scheduler.spi.params.base.Validate;

import java.util.ArrayList;
import java.util.List;

import static com.central.scheduler.spi.params.base.FormType.INPUT;

/**
 * @author Tindy
 * @date 2021/11/15
 * @describe
 * Text param
 */
public class InputParam extends PluginParams {

    private InputParam(Builder builder) {
        super(builder);
    }

    private InputParamProps props;

    public static Builder newBuilder(String name, String title) {
        return new Builder(name, title);
    }

    public static class Builder extends PluginParams.Builder {

        public Builder(String name, String title) {
            super(name, INPUT, title);
        }

        private InputParamProps props;

        public Builder setProps(InputParamProps props) {
            this.props = props;
            return this;
        }

        public Builder setPlaceholder(String placeholder) {
            if (this.props == null) {
                this.setProps(new InputParamProps());
            }

            this.props.setPlaceholder(placeholder);
            return this;
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        public Builder setInfo(String info) {
            this.info = info;
            return this;
        }

        public Builder setValue(Object value) {
            this.value = value;
            return this;
        }

        public Builder setValidateList(List<Validate> validateList) {
            this.validateList = validateList;
            return this;
        }

        public Builder addValidate(Validate validate) {
            if (this.validateList == null) {
                this.validateList = new ArrayList<>();
            }
            this.validateList.add(validate);
            return this;
        }

        public Builder setHidden(Boolean hidden) {
            this.hidden = hidden;
            return this;
        }

        public Builder setDisplay(Boolean display) {
            this.display = display;
            return this;
        }

        @Override
        public InputParam build() {
            return new InputParam(this);
        }
    }

    @Override
    public InputParamProps getProps() {
        return props;
    }
}

